package org.example.student_system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.student_system.aop.anno;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RequiredArgsConstructor
@Slf4j
@RestController
@Tag(name = "Ai对话")
public class ChatController {

    private final ChatClient chatClient;

    @anno
    @GetMapping(value = "/chat", produces = "text/html;charset=utf-8")
    @Operation(summary = "Ai对话")
    public Flux<String> chat(String msg,String id) {
        log.info("提问: {}", msg);
        Flux<String> content = chatClient.prompt()
                .user(msg)
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, id))
                .stream()
                .content();
        return content;
    }
}